<link rel="stylesheet" href="/assets/libs/editormd/css/editormd.css"/>
<style>
    .layui-textarea{
        min-height: auto !important;
    }
</style>
<div class="layui-form" id="layuiadmin-form-admin" lay-filter="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">
    <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
	            <span style="color: red; font-size: 12px;float: left;
				    display: block;
				    padding: 9px 36px;
				    font-weight: 400;
				    line-height: 20px;
				    text-align: right;">备注:共有2种状态,分别为直接提交审核和存入草稿箱等待提交,默认为存入草稿箱状态</span>
    </div>

    <div class="layui-row">
        <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
            <div class="layui-form-item">
                <label class="layui-form-label">选择工作流</label>
                <div class="layui-input-block">
                    <select name="flow_id" lay-verify="required" lay-search="" disabled>
                        <option value="">直接选择或搜索选择</option>
                        {foreach $flow as $vo}
                        <option value="{$vo.id}" selected>{$vo.flowcode}-{$vo.flowname}</option>
                        {/foreach}

                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    提交状态
                </label>
                <div class="layui-input-block">
                    <input type="checkbox" lay-filter="switch" name="switch" lay-skin="switch" lay-text="提交|草稿箱">
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    日志年份
                </label>
                <div class="layui-input-block">
                    <select name="journal_year" id="journal_year" lay-verify="required"
                            lay-filter="journal_year" lay-search="">
                        <option value="">请选择日志类别</option>
                        <option value="2020">2020</option>
                        <option value="2021" >2021</option>
                        <option value="2022" selected>2022</option>
                        <option value="2023">2023</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    日志类别
                </label>
                <div class="layui-input-block">
                    <select name="journal_type_id" id="journal_type_id" lay-verify="required"
                            lay-filter="journal_type_id" lay-search="" disabled>
                        <option value="">请选择日志类别</option>
                        {foreach $journal_type as $key=>$vo}
                        <option value="{$vo.id}" selected>{$vo.name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    人员名称
                </label>
                <div class="layui-input-block">
                    <input autocomplete="off" class="layui-input" id="period" name="admin_name"
                           value="{$username ?? ''}" placeholder="请输入人员名称" required="" type="text" readonly/>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md4" style="display: none">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    所属部门
                </label>
                <div class="layui-input-block">
                    <input autocomplete="off" class="layui-input" value="{$group_name ?? ''}" name="group_name"
                           placeholder="请输入所属部门" required="" type="text"/>
                </div>
            </div>
        </div>
        <div id="xinzeng"></div>
        <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    内容填写
                </label>
                <div class="layui-input-block">
                   <table class="layui-table">
                       <tr>
                       <tr>
                           <th style="text-align: center;width: 10%">星期</th>
                           <th style="text-align: center; width: 80%">今日工作</th>
                           <th style="text-align: center;  width: 10%">完成情况</th>
                       </tr>
                       </tr>
                       <tr>
                           <td style="text-align: center;">
                               <input type="hidden" name="xingqi[]" value="周一">周一
                           </td>
                           <td style="text-align: center;">
                               <textarea rows="1" class="layui-textarea" cols="50" id="one" name="one[]"></textarea>
<!--                               <input type="text" class="layui-input" id="one" name="one[]" />-->
                           </td>
                           <td style="text-align: center;">
                               <input type="text" class="layui-input" id="jindu"  name="jindu[]" />
                           </td>
                       </tr>
                       <tr>
                           <td style="text-align: center;">
                               <input type="hidden" name="xingqi[]" value="周二">周二
                           </td>
                           <td style="text-align: center;">
                               <textarea rows="1" class="layui-textarea" cols="50" id="one" name="one[]"></textarea>
                           </td>
                           <td style="text-align: center;">
                               <input type="text" class="layui-input" id="jindu"   name="jindu[]" />
                           </td>
                       </tr>
                       <tr>
                           <td style="text-align: center;">
                               <input type="hidden" name="xingqi[]" value="周三">周三

                           </td>
                           <td style="text-align: center;">
                               <textarea rows="1" class="layui-textarea" cols="50" id="one" name="one[]"></textarea>
                           </td>
                           <td style="text-align: center;">
                               <input type="text" class="layui-input" id="jindu" name="jindu[]" />
                           </td>
                       </tr>
                       <tr>
                           <td style="text-align: center;">
                               <input type="hidden" name="xingqi[]" value="周四">
                               周四
                           </td>
                           <td style="text-align: center;">
                               <textarea rows="1" class="layui-textarea" cols="50" id="one" name="one[]"></textarea>
                           </td>
                           <td style="text-align: center;">
                               <input type="text" class="layui-input" id="jindu" name="jindu[]" />
                           </td>
                       </tr>
                       <tr>
                           <td style="text-align: center;">
                               <input type="hidden" name="xingqi[]" value="周五">
                               周五

                           </td>
                           <td style="text-align: center;">
                               <textarea rows="1" class="layui-textarea" cols="50" id="one" name="one[]"></textarea>
                           </td>
                           <td style="text-align: center;">
                               <input type="text" class="layui-input" id="jindu" name="jindu[]" />
                           </td>
                       </tr>
                       <tr>
                           <td style="text-align: center;">
                               <input type="hidden" name="xingqi[]" value="周六">
                               周六
                           </td>
                           <td style="text-align: center;">
                               <textarea rows="1" class="layui-textarea" cols="50" id="one" name="one[]"></textarea>
                           </td>
                           <td style="text-align: center;">
                               <input type="text" class="layui-input" id="jindu" name="jindu[]" />
                           </td>
                       </tr>
                       <tr>
                           <td style="text-align: center;">
                               <input type="hidden" name="xingqi[]" value="周日">
                               周日
                           </td>
                           <td style="text-align: center;">
                               <textarea rows="1" class="layui-textarea" cols="50" id="one" name="one[]"></textarea>
                           </td>
                           <td style="text-align: center;">
                               <input type="text" class="layui-input" id="jindu" name="jindu[]" />
                           </td>
                       </tr>
                   </table>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="LAY-user-back-submit" id="LAY-user-back-submit" value="确认">
        </div>
    </div>
</div>
<script src="/static/admin/layui/layui.js">
</script>
<script src="/static/admin/video/jquery.js"></script>
<script src="/assets/libs/editormd/editormd.min.js"></script>
<script>
    layui.config({
        base: '/static/admin/' //静态资源所在路径
    }).extend({
        index: 'lib/index', //主入口模块
        treeTable: '../admin/lib/extend/authtree'
    }).use(['index', 'form'], function () {
        var $ = layui.$, form = layui.form;

        if ($("#journal_type_id").val() != "" || $("#journal_type_id").val() != null || $("#journal_type_id").val() != "undefined" || $("#journal_type_id").val() != undefined){
            var html = "";
            var str = "";
            $.ajax({
                url: "{:url('journal/select_type')}",
                type: "post",
                data: {'year':$("#journal_year").val() ,'id': $("#journal_type_id").val()},
                dataType: "json",
                success: function (res) {
                    var data = eval('(' + res + ')');
                    $("#xinzeng").empty();
                    html += "<div class=\"layui-col-xs12 layui-col-sm6 layui-col-md4\">";
                    html += "<div class=\"layui-form-item\">";
                    html += "<label class=\"layui-form-label\">第x" + $("#journal_type_id option:selected").text() + "</label>";
                    html += "<div class=\"layui-input-block\">";
                    html += "<select name=\"is_week\" id=\"is_week\" lay-verify=\"required\" lay-filter=\"is_week\">";
                    html += "<option value=\"\">请选择日志类别</option>";
                    str += "<div class=\"layui-col-xs12 layui-col-sm6 layui-col-md4\">";
                    str += "<div class=\"layui-form-item\">";
                    str += "<label class=\"layui-form-label\">所属范围</label>";
                    str += "<div class=\"layui-input-block\">";
                    $.each(data, function (index, el) {
                        if (el.now == true) {
                            html += "<option value=\"" + el.detail + "\" data-name=\"" + el.fanwei + "\" selected>" + el.detail + "</option>";
                            str += "<input class=\"layui-input\" name=\"week_time\" id=\"week_time\" placeholder=\"请输入所属范围\" value=" + el.fanwei + " required=\"\" type=\"text\" readonly /> ";
                        } else {
                            html += "<option value=\"" + el.detail + "\"  data-name=\"" + el.fanwei + "\">" + el.detail + "</option>";
                        }
                    });
                    html += " </select>";
                    html += "</div></div></div>";
                    str += "</div></div></div>";
                    $("#xinzeng").append(html);
                    $("#xinzeng").append(str);
                    form.render('select');
                }
            });
        }

        form.on('select(journal_year)',function (data) {
            var html = "";
            var str = "";
            $.ajax({
                url: "{:url('journal/select_type')}",
                type: "post",
                data: {'year':data.value,'id': $("#journal_type_id").val()},
                dataType: "json",
                success: function (res) {
                    var data = eval('(' + res + ')');
                    $("#xinzeng").empty();
                    html += "<div class=\"layui-col-xs12 layui-col-sm6 layui-col-md4\">";
                    html += "<div class=\"layui-form-item\">";
                    html += "<label class=\"layui-form-label\">第x" + $("#journal_type_id option:selected").text() + "</label>";
                    html += "<div class=\"layui-input-block\">";
                    html += "<select name=\"is_week\" id=\"is_week\" lay-verify=\"required\" lay-filter=\"is_week\">";
                    html += "<option value=\"\">请选择日志类别</option>";
                    str += "<div class=\"layui-col-xs12 layui-col-sm6 layui-col-md4\">";
                    str += "<div class=\"layui-form-item\">";
                    str += "<label class=\"layui-form-label\">所属范围</label>";
                    str += "<div class=\"layui-input-block\">";
                    $.each(data, function (index, el) {
                        if (el.now === true) {
                            html += "<option value=\"" + el.detail + "\" data-name=\"" + el.fanwei + "\" selected>" + el.detail + "</option>";
                            str += "<input class=\"layui-input\" name=\"week_time\" id=\"week_time\" placeholder=\"请输入所属范围\" value=" + el.fanwei + " required=\"\" type=\"text\" readonly /> ";
                        }else {
                            html += "<option value=\"" + el.detail + "\"  data-name=\"" + el.fanwei + "\">" + el.detail + "</option>";
                            str = "<div class=\"layui-col-xs12 layui-col-sm6 layui-col-md4\">" +
                                "<div class=\"layui-form-item\">" +
                                "<label class=\"layui-form-label\">所属范围</label>" +
                                "<div class=\"layui-input-block\">" +
                                "<input class=\"layui-input\" name=\"week_time\" id=\"week_time\" placeholder=\"请输入所属范围\" value=" + el.fanwei + " required=\"\" type=\"text\" readonly /></div></div></div> ";
                        }
                    });
                    html += " </select>";
                    html += "</div></div></div>";
                    str += "</div></div></div>";
                    $("#xinzeng").append(html);
                    $("#xinzeng").append(str);
                    form.render('select');
                }
            });
        });


        // form.on('select(journal_type_id)', function (data) {
        //     console.log(12)
        //     var html = "";
        //     var str = "";
        //     $.ajax({
        //         url: "{:url('journal/select_type')}",
        //         type: "post",
        //         data: {'year':$("#journal_year").val(),'id': data.value},
        //         dataType: "json",
        //         success: function (res) {
        //             var data = eval('(' + res + ')');
        //             $("#xinzeng").empty();
        //             html += "<div class=\"layui-col-xs12 layui-col-sm6 layui-col-md4\">";
        //             html += "<div class=\"layui-form-item\">";
        //             html += "<label class=\"layui-form-label\">第x" + $("#journal_type_id option:selected").text() + "</label>";
        //             html += "<div class=\"layui-input-block\">";
        //             html += "<select name=\"is_week\" id=\"is_week\" lay-verify=\"required\" lay-filter=\"is_week\">";
        //             html += "<option value=\"\">请选择日志类别</option>";
        //             str += "<div class=\"layui-col-xs12 layui-col-sm6 layui-col-md4\">";
        //             str += "<div class=\"layui-form-item\">";
        //             str += "<label class=\"layui-form-label\">所属范围</label>";
        //             str += "<div class=\"layui-input-block\">";
        //             $.each(data, function (index, el) {
        //                 console.log(el)
        //                 if (el.now == true) {
        //                     html += "<option value=\"" + el.detail + "\" data-name=\"" + el.fanwei + "\" selected>" + el.detail + "</option>";
        //                     str += "<input class=\"layui-input\" name=\"week_time\" id=\"week_time\" placeholder=\"请输入所属范围\" value=" + el.fanwei + " required=\"\" type=\"text\" readonly /> ";
        //                 } else {
        //                     html += "<option value=\"" + el.detail + "\"  data-name=\"" + el.fanwei + "\">" + el.detail + "</option>";
        //                 }
        //             });
        //             html += " </select>";
        //             html += "</div></div></div>";
        //             str += "</div></div></div>";
        //             $("#xinzeng").append(html);
        //             $("#xinzeng").append(str);
        //             form.render('select');
        //         }
        //     });
        // });

        form.on('select(is_week)', function (event) {
            var fanwei = event.elem[event.elem.selectedIndex].getAttribute('data-name');
            // console.log(pid)
            // var fanwei = $('#is_week').find("option:selected").data("name");
            $('#week_time').val(fanwei);
        });
    });
</script>